package org.sith.taskrunner.gwt.client;

import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.core.client.EntryPoint;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TaskRunner implements EntryPoint {
    @Override
    public void onModuleLoad() {

        AppController appController = new AppController(new SimpleEventBus());

        appController.go(RootLayoutPanel.get());
//        RootPanel.get("main").add(new Label("Hello world"));
        /* *//*ButtonsWidget buttonsWidget = new ButtonsWidget();
        RootPanel.get("buttons").add(buttonsWidget);
        RootPanel.get("adminControls").add(new AdminButtonsWidget());*//*

        DecoratedStackPanel stackPanel = new DecoratedStackPanel();
//                                stackPanel.setWidth("20%");

        stackPanel.add(new Label("One Label"),"One");
        stackPanel.add(new Label("Two Label"),"Two");
        stackPanel.add(new Label("Three Label"),"Three");



       *//* StackLayoutPanel s = new StackLayoutPanel(Style.Unit.EM);
        s.add(new Label("this content"), new Label("this"), 10);
        s.add(new Label("that content"), new Label("that"), 10);
        s.add(new Label("the other content"), new Label("the other"), 10);


        s.setWidth("100%");*//*
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("30%");
        panel.add(stackPanel);
        panel.setHeight("400px");
        *//*DockLayoutPanel p = new DockLayoutPanel(Style.Unit.EM);

        p.addNorth(new HTML("north"), 2);
        p.addSouth(new HTML("south"), 2);
        p.addEast(new HTML("east"), 2);
        p.addWest(s, 4);
        p.add(new HTML("center"));*//*
        RootLayoutPanel rp = RootLayoutPanel.get();
        rp.add(panel);

//        RootPanel.get("main").add(p);*/
    }


    /*  *//**
     * The message displayed to the user when the server cannot be reached or
     * returns an error.
     *//*
    private static final String SERVER_ERROR = "An error occurred while "
            + "attempting to contact the server. Please check your network "
            + "connection and try again.";

    *//**
     * Create a remote service proxy to talk to the server-side Greeting service.
     *//*
    private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

    *//**
     * This is the entry point method.
     *//*
    public void onModuleLoad() {



        HelloWorld helloWorld = new HelloWorld();
        RootPanel panel = RootPanel.get("testField");
        panel.add(helloWorld);

        TaskRunnerMessages messages = GWT.create(TaskRunnerMessages.class);
        final Button sendButton = new Button(messages.okButton());
        final TextBox nameField = new TextBox();
        nameField.setText("GWT User");
        final Label errorLabel = new Label();

        // We can add style names to widgets
        sendButton.addStyleName("sendButton");

        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element
        RootPanel.get("nameFieldContainer").add(nameField);
        RootPanel.get("sendButtonContainer").add(sendButton);
        RootPanel.get("errorLabelContainer").add(errorLabel);

        // Focus the cursor on the name field when the app loads
        nameField.setFocus(true);
        nameField.selectAll();

        // Create the popup dialog box
        final DialogBox dialogBox = new DialogBox();
        dialogBox.setText("Remote Procedure Call");
        dialogBox.setAnimationEnabled(true);
        final Button closeButton = new Button("Close");
        // We can set the id of a widget by accessing its Element
        closeButton.getElement().setId("closeButton");
        final Label textToServerLabel = new Label();
        final HTML serverResponseLabel = new HTML();
        VerticalPanel dialogVPanel = new VerticalPanel();
        dialogVPanel.addStyleName("dialogVPanel");
        dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
        dialogVPanel.add(textToServerLabel);
        dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
        dialogVPanel.add(serverResponseLabel);
        dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
        dialogVPanel.add(closeButton);
        dialogBox.setWidget(dialogVPanel);

        // Add a handler to close the DialogBox
        closeButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                dialogBox.hide();
                sendButton.setEnabled(true);
                sendButton.setFocus(true);
            }
        });

        // Create a handler for the sendButton and nameField
        class MyHandler implements ClickHandler, KeyUpHandler {
            *//**
     * Fired when the user clicks on the sendButton.
     *//*
            public void onClick(ClickEvent event) {
                sendNameToServer();
            }

            *//**
     * Fired when the user types in the nameField.
     *//*
            public void onKeyUp(KeyUpEvent event) {
                if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                    sendNameToServer();
                }
            }

            *//**
     * Send the name from the nameField to the server and wait for a response.
     *//*
            private void sendNameToServer() {
                // First, we validate the input.
                errorLabel.setText("");
                String textToServer = nameField.getText();
                if (!FieldVerifier.isValidName(textToServer)) {
                    errorLabel.setText("Please enter at least four characters");
                    return;
                }

                // Then, we send the input to the server.
                sendButton.setEnabled(false);
                textToServerLabel.setText(textToServer);
                serverResponseLabel.setText("");
                greetingService.greetServer(textToServer, new AsyncCallback<String>() {
                    public void onFailure(Throwable caught) {
                        // Show the RPC error message to the user
                        dialogBox.setText("Remote Procedure Call - Failure");
                        serverResponseLabel.addStyleName("serverResponseLabelError");
                        serverResponseLabel.setHTML(SERVER_ERROR);
                        dialogBox.center();
                        closeButton.setFocus(true);
                    }

                    public void onSuccess(String result) {
                        dialogBox.setText("Remote Procedure Call");
                        serverResponseLabel.removeStyleName("serverResponseLabelError");
                        serverResponseLabel.setHTML(result);
                        dialogBox.center();
                        closeButton.setFocus(true);
                    }
                });
            }
        }

        // Add a handler to send the name to the server
        MyHandler handler = new MyHandler();
        sendButton.addClickHandler(handler);
        nameField.addKeyUpHandler(handler);


    }*/
}
